package com.moter.demo01.juc.alllocks.deadlock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 可重入锁造成的死锁
 */
public class DeadReentrantLock {
    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                lock.lock();
                lock.lock();
                try {
                    System.out.println(Thread.currentThread().getName());
                }finally {
                    //锁几次就要解锁几次，如果少了就会造成死锁
                    lock.unlock();
                    lock.unlock();
                    lock.unlock();
                }
            }).start();
        }
    }
}
